package com.betty.cscams.controller;

import java.util.List;

import com.betty.cscams.common.http.HttpResult;
import com.betty.cscams.common.page.PageRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;



import com.betty.cscams.entity.SysNotice;
import com.betty.cscams.service.SysNoticeService;

/**
 * ---------------------------
 *  (SysNoticeController)         
 * ---------------------------
 * 时间：  2022-03-16 20:41:54
 * ---------------------------
 */
@RestController
@RequestMapping("sysNotice")
public class SysNoticeController {

	@Autowired
	private SysNoticeService sysNoticeService;

	/**
	 * 保存
	 * @param record
	 * @return
	 */	
	@PostMapping(value="/save")
	public HttpResult save(@RequestBody SysNotice record) {
		return HttpResult.ok(sysNoticeService.save(record));
	}

    /**
     * 删除
     * @param records
     * @return
     */
	@PostMapping(value="/delete")
	public HttpResult delete(@RequestBody List<SysNotice> records) {
		return HttpResult.ok(sysNoticeService.delete(records));
	}

    /**
     * 基础分页查询
     * @param pageRequest
     * @return
     */    
	@PostMapping(value="/findPage")
	public HttpResult findPage(@RequestBody PageRequest pageRequest) {
		return HttpResult.ok(sysNoticeService.findPage(pageRequest));
	}
	
    /**
     * 根据主键查询
     * @param id
     * @return
     */ 	
	@GetMapping(value="/findById")
	public HttpResult findById(@RequestParam Long id) {
		return HttpResult.ok(sysNoticeService.findById(id));
	}

	/**
	 * 根据主键查询
	 * @return
	 */
	@GetMapping(value="/release")
	public HttpResult release(@RequestParam Long id) {
		SysNotice notice = new SysNotice();
		notice.setStatus(2);
		notice.setId(id);
		return HttpResult.ok(sysNoticeService.save(notice));
	}

	/**
	 * 根据主键查询
	 * @return
	 */
	@GetMapping(value="/offline")
	public HttpResult offline(@RequestParam Long id) {
		SysNotice notice = new SysNotice();
		notice.setStatus(3);
		notice.setId(id);
		return HttpResult.ok(sysNoticeService.save(notice));
	}

	@GetMapping(value="/findList")
	public HttpResult findList() {
		return HttpResult.ok(sysNoticeService.findList());
	}

	@GetMapping(value="/findListByLimit")
	public HttpResult findListByLimit(@RequestParam Integer limit) {
		return HttpResult.ok(sysNoticeService.findListByLimit(limit));
	}
}
